package com.dianning.service.imp;

import java.io.IOException;
import java.io.InputStream;
import java.util.*;

import org.apache.commons.logging.*;

import com.dianning.bean.AdSpace;
import com.dianning.bean.Parameter;
import com.dianning.bean.Visitor;
import com.dianning.comm.Constant;
import com.dianning.dao.AdAdsDAO;
import com.dianning.dao.AdSpaceDAO;
import com.dianning.dao.ParameterDAO;
import com.dianning.dao.VisitorDAO;
import com.dianning.exception.DianningException;
import com.dianning.service.AdService;
import com.dianning.service.Cache;
import com.dianning.service.ParameterService;
import com.dianning.service.VisitorService;

public class ParameterServiceImp implements ParameterService {

	private static final Log logger = LogFactory.getLog(ParameterServiceImp.class);
	
	private ParameterDAO parameterDAO;
	private Cache parameterCache;
	
	public ParameterDAO getParameterDAO() {
		return parameterDAO;
	}

	public void setParameterDAO(ParameterDAO parameterDAO) {
		this.parameterDAO = parameterDAO;
	}
	
	public Parameter findParameterById(long id){
		return this.getParameterDAO().findParameterById(id);
	}

	public Cache getParameterCache() {
		return parameterCache;
	}

	public void setParameterCache(Cache parameterCache) {
		this.parameterCache = parameterCache;
	}

	/**
	 * 获取Parameter对象列表
	 * @param code
	 * @param depth
	 * @param orderby
	 * @param ascOrDesc
	 * @return
	 */
	public List findParameters(String code,int depth,List ids,String orderby, int ascOrDesc){
		if(Constant.USE_CACHE){
			List l = (List) this.getParameterCache().get("[parameter]["+code+"]["+depth+"]["+ids+"]["+orderby+"]["+ascOrDesc+"]");
			if(l == null){
				l = this.getParameterDAO().findParameters(code, depth, ids, orderby, ascOrDesc);
				this.getParameterCache().add("[parameter]["+code+"]["+depth+"]["+ids+"]["+orderby+"]["+ascOrDesc+"]",l);
			}
			return l;
		}else{
			return this.getParameterDAO().findParameters(code, depth, ids, orderby, ascOrDesc);
		}
	}
	
	
}
